package jee.boot.common.service;


import jee.boot.common.basic.TreeService;
import jee.boot.common.cache.CacheDataManager;
import jee.boot.common.dao.DictionaryDao;
import jee.boot.entity.system.Dictionary;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 字典Service
 * 
 * @author zhilei.wang
 * @version 2014-05-16
 */
@Service
public class DictionaryService extends TreeService<DictionaryDao, Dictionary> {
    @Cacheable(value = "sysDict", key = "#entity.entityKey")
    @Override
    public Dictionary get(Dictionary entity) {
        return super.get(entity);
    }
    @Caching(evict = {
            @CacheEvict(value = "sysDict", key = "#entity.entityKey"),
            @CacheEvict(value = CacheDataManager.SYSTEM_CACHE_NAME, key="#entity.cacheKey")
    })
    @Override
    public void save(Dictionary entity) {
        super.save(entity);
    }
    @Caching(evict = {
            @CacheEvict(value = "sysDict", key = "#entity.entityKey"),
            @CacheEvict(value =CacheDataManager.SYSTEM_CACHE_NAME, key="#entity.cacheKey")
    })
    @Override
    public void update(Dictionary entity) {
        super.update(entity);
    }
    @Caching(evict = {
            @CacheEvict(value = "sysDict", key = "#entity.entityKey"),
            @CacheEvict(value = CacheDataManager.SYSTEM_CACHE_NAME, key="#entity.cacheKey")
    })
    @Override
    public void delete(Dictionary entity) {
        super.delete(entity);
    }

    /**
     * 初始化主数据的缓存进入redis中
     * @param entity
     */
    @Cacheable(value = CacheDataManager.SYSTEM_CACHE_NAME, key = "#entity.cacheKey")
    public List<Dictionary> initCache(Dictionary entity) {
        return findList(entity);
    }

    /**
     * 查询所有字典类型
     * @param entity
     * @return
     */
    public List<Dictionary> findTypeList(Dictionary entity){
        return dao.findTypeList(entity);
    }
}
